<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false"%>
<html>
<head>
    <title>首拖件规则管理</title>
</head>
<body>
<input type="hidden" id="majorRule" value="${majorRule}"/>
<div ng-app="myApp" ng-controller="MajorCtrl">
    <ui-form key="majorUpdate" column="1">
        <input name="id" type="hidden" value="${majorRule.id}"/>
        <ui-form-select-remote label="供应商:" url="system/supplier/listall" value-name="code" text-name="name" name="supplierCode" value="${majorRule.supplierCode}"></ui-form-select-remote>
        <ui-form-select name="state" label="激活状态:" value="${majorRule.state}">
            <option value="0">否</option>
            <option value="1">是</option>
        </ui-form-select>
        <ui-form-select-remote   label="解析器类:" url="rule/major/parserstransform" value-name="parser"  text-name="exhibition" name="parser" value="${majorRule.parser}"></ui-form-select-remote>
        <ui-form-textarea name="description" label="规则描述:" value="${majorRule.description}" readOnly="true"></ui-form-textarea>
        <ui-form-textarea name="initJson" label="解析类初始化参数:" value="<c:out value='${majorRule.initJson}'/>" ></ui-form-textarea>
    </ui-form>
</div>
<script>
    angular.module('myApp', ['ui.form']);
    angular.module('myApp').controller('MajorCtrl', function ($scope) {
        $scope.$on('ui.form.submit',function (event,param) {
            $.ajax({
                url:"rule/major/update",
                type:"post",
                data:param
            }).done(function (result) {
                if(result.code=='0000'){
                    toastr.success(result.data);
                    setTimeout(function () {
                        window.location.href="rule/major/index.html";
                    },1500);
                }else{
                    toastr.error(result.msg);
                }
            }).fail(function (err) {

            });
        })
    });
    $(document).ready(function () {
        $("select[name='parser']").bind('change',function(){
            var value=this.value;
            $.ajax({
                url:"rule/major/getinfos",
                type:"get",
                data:{parser:value},
                success:function (result) {
                    var data=result.data||[];
                    var str1="";
                    var str2="";
                    for (var i in data){
                        if(data[i].parser== value){
                            str1=data[i].description;
                            str2=data[i].initJson;
                        }
                    }
                $("textarea[name='description']").val(str1);
                $("textarea[name='initJson']").val(str2);
                },
              fail:function (result) {
                  toastr.error(result.msg);
              }
            });



        });
    });
</script>
</body>
</html>